import {
	createI18n
} from 'vue-i18n'

import zhLocale from './lang/zh'
import enLocale from './lang/en'

import store from '@/store'

const messages = {
	en: {
		msg: {
			...enLocale
		}
	},

	zh: {
		msg: {
			...zhLocale
		}
	}
}

function getLanguage() {
	return store && store.getters && store.getters.language
}


const i18n = createI18n({
	// 使用组合式API
	legacy: false,
	// 全局使用t函数
	globalInjection: true,
	locale: getLanguage() || 'zh',
	messages
})

export default i18n
